package com.example.monitor.controller;

import com.example.config.ResponseBean;
import com.example.config.UnicomResponseEnums;
import com.example.util.SigarUtils;
import org.hyperic.sigar.SigarException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

@RestController()
@RequestMapping("/monitor/server")
public class serverController {


    @GetMapping("/getServerConfig")
    public ResponseBean<UnicomResponseEnums> getServerConfig(){
        System.out.println("开始获取系统信息");
        SigarUtils sigarUtils=new SigarUtils();
        sigarUtils.initSigar();
        Map<String, Object> map = new HashMap<>();
        try {
            map.put("cpu", sigarUtils.cpu());
            map.put("mem", sigarUtils.memory());
            map.put("property", sigarUtils.property());
            map.put("file", sigarUtils.file());
            System.out.println(map);
        } catch (SigarException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseBean(true,map,UnicomResponseEnums.SUCCESS_OPTION);
    }
}
